package com.share;

/**
 * @desc: CAS 模拟
 * @author:caifan
 * @date:2022/4/5
 */
public class SimulatedCAS {
    private int value;

    public synchronized int compareAndSwap(int expectedValue, int newValue) {
        int oldValue = value;
        if (oldValue == expectedValue) {
            return newValue;
        }
        return oldValue;
    }
}
